<template>
    <el-dialog title="缺陷类型" :close-on-click-modal="false" :visible.sync="visible" :append-to-body="true"
      class="SHZY-dialog SHZY-dialog_center" lock-scroll width="700px">
      <el-timeline class="timeline">
        <el-timeline-item v-for="(item, index) in defectList" :key="index">
          <div class="el-timeline-content">
            <p class="text">
              <el-tag size="medium" class="def">{{ item.defectName }}</el-tag>
              <el-tag size="small" effect="dark" style="margin-left: 5px;">{{ item.defectQty }}</el-tag>
              <el-tag size="small" v-if="item.severity == '高'" type="danger" effect="dark" style="margin-left: 5px;">{{
                item.severity }}</el-tag>
              <el-tag size="small" v-if="item.severity == '中'" type="warning" effect="dark" style="margin-left: 5px;">{{
                item.severity }}</el-tag>
              <el-tag size="small" v-if="item.severity == '低'" type="info" effect="dark" style="margin-left: 5px;">{{
                item.severity }}</el-tag>
                <el-tag size="small" style="margin-left: 5px;" v-if="item.fileInfo.length">
                 <a v-for="file in item.fileInfo" :key="file.fileId" @click="handleClick(file)">
                      <i class="el-icon-paperclip" :title="file.name"></i>
                 </a>
                </el-tag>
            </p>
            <p class="text">
              {{ item.remark }}
            </p>
          </div>
        </el-timeline-item>
      </el-timeline>
      
    </el-dialog>
</template>

<script>
import { mapGetters } from "vuex"
import { getDownloadUrl } from '@/api/common'
export default {
  computed: {
    ...mapGetters(['userInfo'])
  },
  data() {
    return {
      visible: false,
      text: '',
      defectList: [],
    //   dataForm: {
    //     inspectionItem: "",
    //     number: 0,
    //     defect: "",
    //     defectName: "",
    //     defectQty: 1,
    //     severity: "",
    //     fileInfo: []
    //   },
      
    }
  },
  methods: {
    init(data) {
      this.visible = true
      this.defectList = data
    },
    handleClick(file) {
      // 点击下载文件
      if (!file.fileId) return
      getDownloadUrl('annex', file.fileId).then(res => {
        this.shzy.downloadFile(res.data.url)
      })
    },
    handleDel(index, id) {
      this.$confirm(this.$t('common.delTip'), this.$t('common.tipTitle'), {
        type: 'warning'
      }).then(() => {
        delInspectionitemdefect(id).then(res => {
          this.$message({
            type: 'success',
            message: res.msg,
            onClose: () => {
              this.defectList.splice(index, 1);
            }
          });
        })
        this.$message({ type: 'success', message: res.msg });
      }).catch(() => { });
    },
  }
}
</script>


<style lang="scss" scoped>
.timeline {
  padding-top: 30px;
}

>>>.el-timeline-content {
  p {
    padding: 0;
    margin: 0;
  }

  .text {
    line-height: 15px;
    margin-bottom: 10px;
    color: #475059;
    font-size: 12px;
  }

  .time {
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    opacity: 0.6;

    .del {
      display: none;
      color: rgb(255, 91, 91);
      cursor: pointer;

      i {
        margin-right: 5px;
      }
    }
  }

  &:hover {
    .del {
      display: block;
    }
  }
  .def{
    white-space: normal;
    height: auto;
  }
}</style>